require "rexml/document"
require "step"
require "snippet"
include REXML

module LWA
  class Testcase

    attr_reader :case_element
    attr_reader :step_list

    def initialize(case_element)
      @case_element = case_element
      @step_list = create_step_list
    end

    def create_step_list
      step_list = Array.new
      @case_element.elements.each do |each_element|
        case each_element.name
        when /Step/
          step_list.push(Step.new(each_element))
        when /Snippet/
          Snippet.new(each_element).create_step_list.each { |each_step| step_list.push(each_step) }
        else
          raise "ERROR: Step (#{each_element.name}) is not recognized."
        end
      end
      return step_list
    end

  end
end
